<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('产权信息变更记录') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('基金全称')" prop="fundName">
        <el-input
          v-model="queryParams.fundName"
          :placeholder="$t('基金全称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('事件发生日')" prop="eventDate">
        <DatePicker v-model="eventDates" type="daterange" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="propertyFundList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金全称')" align="center" prop="fundName" width="250">
        <template slot-scope="scope">
          <el-link type="primary" @click="updateHandle(scope.row)"><span>{{ scope.row.fundName }}</span></el-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('一级登记类型')" align="center" prop="levelOneRegistrationType" :formatter="levelOneRegistrationTypeFormat" width="250" />
      <el-table-column :label="$t('二级登记类型')" align="center" prop="levelTwoRegistrationType" :formatter="levelTwoRegistrationTypeFormat" width="250" />
      <el-table-column :label="$t('事件发生日')" align="center" prop="eventDate" width="170">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.eventDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('变更信息')" align="center" prop="changeInformation" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改产权信息对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <propertyFundForm ref="propertyFundForm" />
    </el-dialog>
  </div>
</template>

<script>
import {
  listChangePropertyFund
} from '@/api/fund/property/propertyFund'
import propertyFundForm from './propertyFundForm.vue'
export default {
  components: {
    propertyFundForm
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 产权信息表格数据
      propertyFundList: [],
      // 弹出层标题
      title: '产权信息',
      // 是否显示弹出层
      formOpen: false,
      // 一级登记类型字典
      levelOneRegistrationTypeOptions: [],
      cq_levelTwoRegistrationTypeOptions: [],
      zy_levelTwoRegistrationTypeOptions: [],
      // 基金类型字典
      fundTypeOptions: [],

      eventDates: [],
      // 查询参数
      queryParams: {
        fundName: undefined,
        fundAbbreviation: undefined,
        fundType: undefined,
        establishTime: undefined,
        fundManagementCompanyName: undefined,
        startDate: undefined,
        endDate: undefined,
        changeId: this.$route.query.id,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
    this.getDicts('fund_registration_type').then(response => {
      this.levelOneRegistrationTypeOptions = response.data
    })
    this.getDicts('property_fund_type').then(response => {
      this.fundTypeOptions = response.data
    })
    this.getDicts('property_rights_change_fund').then(response => {
      this.cq_levelTwoRegistrationTypeOptions = response.data
    })
    this.getDicts('possession_registration_fund').then(response => {
      this.zy_levelTwoRegistrationTypeOptions = response.data
    })
  },
  mounted() {
    this.$bus.$emit('async_done')
  },
  methods: {
    /** 查询产权信息列表 */
    getList() {
      this.loading = true
      if (this.eventDates !== null && this.eventDates.length > 1) {
        this.queryParams.startDate = this.eventDates[0]
        this.queryParams.endDate = this.eventDates[1]
      } else {
        this.queryParams.startDate = undefined
        this.queryParams.endDate = undefined
      }
      listChangePropertyFund(this.queryParams).then(response => {
        this.propertyFundList = response.rows
        this.total = response.total
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    // 一级登记类型字典翻译
    levelOneRegistrationTypeFormat(row, column) {
      console.log(column)
      return this.selectDictLabel(this.levelOneRegistrationTypeOptions, row.levelOneRegistrationType)
    },
    // 基金类型字典翻译
    fundTypeFormat(row, column) {
      console.log(column)
      return this.selectDictLabel(this.fundTypeOptions, row.fundType)
    },
    // 二级产权登记类型字典翻译
    levelTwoRegistrationTypeFormat(row, column) {
      console.log(column)
      if (row.levelOneRegistrationType === 'ZYDJ') {
        return this.selectDictLabel(this.zy_levelTwoRegistrationTypeOptions, row.levelTwoRegistrationType)
      } else {
        return this.selectDictLabel(this.cq_levelTwoRegistrationTypeOptions, row.levelTwoRegistrationType)
      }
    },

    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        fundId: undefined,
        levelOneRegistrationType: undefined,
        levelTwoRegistrationType: undefined,
        fundName: undefined,
        fundAbbreviation: undefined,
        fundType: undefined,
        establishTime: undefined,
        duration: undefined,
        detailsRegistered: undefined,
        fundManagementCompany: undefined,
        managementAmountRatio: undefined,
        groupDischargePeopleNumber: undefined,
        chairman: undefined,
        actuallyManaged: undefined,
        investmentCommitteePeopleNumber: undefined,
        fundContact: undefined,
        fundContactNumber: undefined,
        totalFundSize: undefined,
        mainInvestment: undefined,
        totalInvestedCapital: undefined,
        existingProjectsNumber: undefined,
        receiveDividends: undefined,
        fundValuation: undefined,
        fundValuationTime: undefined,
        remark: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.eventDates = []
      this.queryHandle()
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.propertyFundForm.init(row)
      })
    }
  }
}
</script>
